package com.foreknow.demo12.exer;

/**
 * @author shkstart
 * @create 2021-08-02 13:54
 */

import java.util.*;

/**
 * 二、实现一个随机分组的程序, 随便选择今年NBA中16支队伍, 然后将这16支队伍放进一个List里面,
 * 并在控制台上随机分成4组, 打印出来
 * String nba []= {"骑士","勇士","湖人","热火","老鹰","猛龙","篮网","凯尔特人","小牛","活塞",
 * "公牛","魔术","爵士","开拓","火箭"};
 */
public class ListMapTest1 {
    public static void main(String[] args) {

        String nba[] = {"骑士", "勇士", "湖人", "热火", "老鹰", "猛龙", "篮网", "凯尔特人", "小牛", "活塞",
                "公牛", "魔术", "爵士", "开拓", "火箭", "快船"};
        String[] newnba = new String[nba.length];
        int k = 0;
        int group = 0;
        List<Integer> list = new ArrayList<>();
        while (true) {
            if (list.size() < 16) {
                int random1 = (int) ((Math.random() * 16));//0-15
                if (!list.contains(random1)) {
                    list.add(random1);
                }

            } else {
                break;
            }
        }
        for (int i = 0; i < list.size(); i++) {
            newnba[i] = nba[list.get(i)];

        }

        List<String> list1 = new ArrayList<>();
        List<String[]> list2 = new ArrayList<>();
        String[] group1 = new String[4];
        String[] group2 = new String[4];
        String[] group3 = new String[4];
        String[] group4 = new String[4];
        list2.add(group1);
        list2.add(group2);
        list2.add(group3);
        list2.add(group4);
        for (int i = 0; i < 4; i++) {
            for (int j = i * 4; j < (i + 1) * 4; j++) {
                list2.get(i)[k++] = newnba[j];

                if ((j + 1) % 4 == 0) {
                    group++;
                    k=0;
                }
            }
        }
        for (int i = 0; i < list2.size(); i++) {
            for (int j = 0; j < list2.get(i).length; j++) {
                System.out.print(list2.get(i)[j]+" ");

            }
            System.out.println();
        }
    }

}
